home *** CD-ROM | disk | FTP | other *** search
-
- /****************************************************************************/
- /* DATABOSS MODULE: DB_UTIL.C */
- /* Set the editor TAB size to 3 for correct indentation */
- /****************************************************************************/
-
- #include "db_lsc.h"
-
- #include <conio.h>
- #ifndef __TURBOC__
- #include <graph.h>
- #endif
- #include <io.h>
- #include <process.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include "db_types.h"
- #include "db_conio.h"
- #include "db_crit.h"
- #include "db_curs.h"
- #include "db_date.h"
- #include "db_dos.h"
- #include "db_file.h"
- #include "db_funcs.h"
- #include "db_gvar.h"
- #include "db_heap.h"
- #include "db_key.h"
- #include "db_math.h"
- #include "db_sets.h"
- #include "db_str.h"
- #include "db_win.h"
- #include "db_uwin.h"
- #include "db_util.h"
-
- /********************** GLOBAL INITIALIZED VARIABLES **********************/
-
- byte swc = 31;
- byte sbc = 30;
- byte hcolr = 47;
- byte hbcolr = 46;
- byte hshad = 8;
- uchar hbchrs[] = "═╕│╛═╘│╒";
- bool no_crlf = False; /* SN 3.5 */
- bool ad_crlf = True; /* SN 3.5 */
-
- /**************************** GLOBAL VARIABLES ****************************/
-
- bool badpic,alwaysvalid,fieldchanged;
- int deltas, manstate;
- scrproc savescreenp;
- helpproc morehelp;
- set _PIC_SET;
- bool _upward,_1chwait;
- int pabort,fldnum;
- uchar exitcode;
- byte attrib;
- string compstr;
- pathstr datapath,filname;
- word es_status;
- edthookproc edthook;
- ewsfunctyp ewsfunc;
- iesfunctyp iesfunc;
- sesproctyp sesproc;
- winptr messageWindowPtr; /* SN 3.5 */
-
- /*************************** INTERNAL CONSTANTS ***************************/
-
- #define StartIntWin 0
- #define NumIntWin 4
-
- #define Mono_Mask 0x0030
- #define CO80_Mask 0x0020
- #define CO40_Mask 0x0010
-
- static const byte MONO_ra[] = {7,15};
-
- #define ParmCmd "AV= IV= EV= SNOW="
-
- #define Across 65
- #define Down 13
- static uchar Selectable[Down][Across+1] = {
- {" ─ │ ║ ═ ■ "},
- {" "},
- {" ┌ ┬ ┐ ╒ ╤ ╕ ╓ ╥ ╖ ╔ ╦ ╗ ▄ "},
- {" "},
- {" ├ ┼ ┤ ╞ ╪ ╡ ╟ ╫ ╢ ╠ ╬ ╣ ▌ █ ▐ "},
- {" "},
- {" └ ┴ ┘ ╘ ╧ ╛ ╙ ╨ ╜ ╚ ╩ ╝ ▀ "},
- {" "},
- {" "},
- {" "},
- {" "},
- {" "},
- {" "}};
-
- #define ColSz 15
- #define Colms 4
- #define Lines 13
- #define MinDirSpace 2048
- #define MaxDirEntries 512
- #define BSize 256
-
- /***************************** INTERNAL TYPES *****************************/
-
- typedef char dirnamstr[ColSz + 1];
- typedef dirnamstr direntries[MaxDirEntries];
- typedef direntries *direntptr;
-
- /*************************** INTERNAL VARIABLES ***************************/
-
- static byte lschx,lschy;
- static bool nopics;
- static double savetime;
- static winptr intwin[NumIntWin];
-
- static byte attr_;
- static uchar kb_char_;
- static bool goodch;
- static bool lastchar_,rub_flag_,exit_flag_;
- static int start_,picptr_,txpos_,frac_len_,int_len_;
- static string t_pic_,ts_,savefield_;
- static cursortyp *cursptr_;
- static int xpos_;
- static int ypos_;
- static strptr field_;
- static uchar typ_;
- static strptr pic_;
- static int flen_;
- static byte a_;
- static winptr winp_;
-
- static char parml_[81],prm_[11];
- static pathstr fname_;
-
- static int tpage_,col_,lin_,countf_,apos_;
- static direntptr dirarray_;
- static bool refill_;
-
- static bool initialized = False;
-
- /***************************** IMPLEMENTATION *****************************/
-
- strptr decnumb(string sout, string s)
- {
- strptr scan,store;
-
- scan = s;
- store = sout;
- while (*scan && (*scan++ != *_dcpt))
- *(store++) = '9';
- *store = 0;
- return (fstr(sout,valu(sout) - valu(s),strlen(s),strlen(scan)));
- }
-
- void strsop(strptr s1, string s2, uchar op)
- {
- int l, d;
- double r1, r2;
- string tempString; /* SN 3.5 */
- int isFloat; /* SN 3.5 */
-
- l = strlen(s1);
- d = strposch(*_dcpt,s1) + 1;
- if (d > 0) d = l - d; /* SN 3.5 */
-
- r1 = valu(s1);
- r2 = valu(s2);
- switch (op) {
- case '+' : r1 += r2; break;
- case '-' : r1 -= r2; break;
- case '*' : r1 *= r2; break; /* SN 3.5 */
- case '/' : r1 /= r2; break; /* SN 3.5 */
- }
- fstr(tempString,r1,l,d);
- strcopy(s1, tempString, 0, l); /* SN 3.5 */
- }
-
- void writeStatusLine(strptr windowMessage)
- {
- if (openwin(0, 1, 25, 80, 1, 79, 79, 8, "\0┐│┘─└│┌", TopCnt, "")) {
- messageWindowPtr = curwin;
- writewxy(windowMessage, 0, 1, 1, messageWindowPtr);
- hidewin(T_ON,messageWindowPtr);
- }
- return;
- }
-
- void chkwrite(int outdev, string wstr, bool cr_lf)
- {
- int bw;
- string ts, ts2;
- uchar ans[2];
- uchar tmps1[2];
-
- pabort = 0;
- if (cr_lf) strconcat(ts,wstr,"\r\n",NULL); else strcpy(ts,wstr);
- do {
- bw = write(outdev,ts,strlen(ts));
- if (bw == -1) {
- pabort = 1;
- writeStatusLine(centre(ts2, LSC_OutputFailure, 80));
- do {
- *ans = upperch(getkey());
- }while ((*ans != _Abort) && (*ans != _Retry));
- if (*ans == _Retry) pabort = -1;
- if (messageWindowPtr) closewin(&messageWindowPtr);
- }
- else {
- pabort = 0;
- if (kpressed()) {
- writeStatusLine(centre(ts2, LSC_EscOrEnter, 80));
- do {
- *ans = getkey();
- }while ((*ans != QitKey) && (*ans != Enter));
- if (*ans == QitKey) pabort = 999;
- else pabort = 0;
- if (messageWindowPtr) closewin(&messageWindowPtr);
- }
- }
- } while (pabort < 0);
- }
-
- void chkwriteCh(int outdev, char wch)
- {
- int bw;
- string ts2;
- uchar ans[2];
- uchar tmps1[2];
-
- pabort = 0;
- do {
- bw = write(outdev,&wch,1);
- if (bw == -1) {
- pabort = 1;
- writeStatusLine(centre(ts2, LSC_OutputFailure, 80));
- do {
- *ans = upperch(getkey());
- }while ((*ans != _Abort) && (*ans != _Retry));
- if (*ans == _Retry) pabort = -1;
- if (messageWindowPtr) closewin(&messageWindowPtr);
- }
- else {
- pabort = 0;
- if (kpressed()) {
- writeStatusLine(centre(ts2, LSC_EscOrEnter, 80));
- do {
- *ans = getkey();
- }while ((*ans != QitKey) && (*ans != Enter));
- if (*ans == QitKey) pabort = 999;
- else pabort = 0;
- if (messageWindowPtr) closewin(&messageWindowPtr);
- }
- }
- } while (pabort < 0);
- }
-
- int _calc_int(string pic)
- {
- return (strlen(pic));
- }
-
- int _calc_frac(string pic)
- {
- return ((pic = strchr(pic,*_dcpt)) == NULL ? 0 : strlen(++pic));
- }
-
- int dotPos(strptr scanString) /* SN 3.5 */
- { /* SN 3.5 */
- int scanOffset; /* SN 3.5 */
- /* SN 3.5 */
- scanOffset = strlen(scanString); /* SN 3.5 */
- while ((scanOffset >= 0) && (*(scanString + scanOffset--) != '.')) continue; /* SN 3.5 */
- return(scanOffset); /* SN 3.5 */
- } /* SN 3.5 */
-
- void printwin(int odev, winptr winp, prtmode pmode)
- {
- uchar wch;
- int i,j,titlelen;
- string tl,tln,bln,rln,lln;
- largebptr lb;
- wintyp twin;
- uchar cstr[2],cstr1[2];
-
- if (winp != NULL) {
- chkwrite(odev,"",True);
- if ((pabort == 0) && (winp->borchrs[0] != '\0')) {
- twin = *winp;
- if (pmode != AllChrs) {
- for (i=0; i < 8; i++)
- twin.borchrs[i] = filterch(twin.borchrs[i],pmode);
- titlelen = strlen(twin.title);
- for (i=0; i < titlelen; i++)
- twin.title[i] = filterch(twin.title[i],pmode);
- }
- get4sides(&twin,tln,bln,rln,lln);
- chkwrite(odev,tln,True);
- }
- lb = winp->winblk;
- for (i=1; i <= winp->mhgt; i++) {
- tl[0] = '\0';
- for (j=1; j <= winp->mwid; j++) {
- wch = (*lb)[(i-1)*winp->mwid+j-1].vchar;
- if (pmode != AllChrs) wch = filterch(wch,pmode);
- strchcat(tl,wch);
- }
- if (winp->borchrs[0] != '\0')
- strconcat(tl,chstr(cstr,lln[i]),tl,chstr(cstr1,rln[i]),NULL);
- if (pabort == 0)
- chkwrite(odev,tl,True);
- }
- if ((pabort == 0) && (winp->borchrs[0] != '\0'))
- chkwrite(odev,bln,True);
- }
- }
-
- strptr expand(strptr sout, strptr instring)
- {
- int i,x,instrlen;
- string work1,work2;
- char *wrk1,*rp;
- bool error;
-
- i = 0;
- error = False;
- work2[0] = '\0';
- instrlen = strlen(instring);
- while ((i < instrlen) && !error) {
- work1[0] = '\0';
- wrk1 = work1;
- if (set_member(_DIGITS,instring[i])) {
- do {
- *wrk1++ = instring[i++];
- } while (set_member(_DIGITS,instring[i]));
- *wrk1 = '\0';
-
- x = ival(work1);
- if (x < 1 || x > 255) error = True;
- /*
- x = (int) strtol(work1,&rp,10);
- if (*rp != '\0') error = True;
- if (x > 255) error = True;
- */
- if (!error) {
- memset(work1,instring[i],x);
- work1[x] = '\0';
- i++;
- strcat(work2,work1);
- }
- }
- else strchcat(work2,instring[i++]);
- }
- if (error) strcpy(sout,"BAD PIC");
- else trim(sout,work2);
- return(sout);
- }
-
- byte piclen(strptr pic, uchar typ)
- {
- int b,tmplen;
- byte fval;
- string tpic;
-
- expand(tpic,pic);
- fval = 0;
- tmplen = strlen(tpic);
- for (b = 0; b < tmplen; b++) {
- if (set_member(_PIC_SET,tpic[b])) fval++;
- }
- if ((typ == _Num) && (strchr(tpic,*_dcpt) != NULL)) fval++;
- return(fval);
- }
-
- bool validate_fpic(strptr instr, strptr picture, uchar typ)
- {
- int pstrlen,plen;
- string tmpstr,tmpstr1,tmpstr2;
-
- pstrlen = strlen(instr);
- plen = piclen(picture,typ);
- if ((plen == 0) || (plen != pstrlen)) {
- clr_line(1);
- writewxy(strconcat(tmpstr,LSC_FldPicMismatch,strip(tmpstr1,istr(tmpstr1,(long) pstrlen,3)),
- LSC_PicIndicatesLen,strip(tmpstr2,istr(tmpstr2,(long) plen,3)),NULL),0x8C,1,1,NULL);
- delayorkey(3.0);
- clr_line(1);
- if (plen < 38)
- writewxy(strconcat(tmpstr,"\"",strcopy(tmpstr1,instr,0,38),"\",\"",
- strcopy(tmpstr2,picture,0,38),"\"",NULL),0x8C,1,1,NULL);
- else
- writewxy(strcopy(tmpstr,instr,0,80),0x8C,1,1,NULL);
- delayorkey(3.0);
- clr_line(1);
- }
- badpic = (bool) (plen != pstrlen);
- return((bool) (!badpic));
- }
-
- strptr pic_fld(strptr sout, strptr field, uchar typ, byte start, byte flen, str20 pic)
- {
- int i, j, int_len, frac_len, tmplen;
- double r_field;
- string temp_fld,ws,t_pic;
- char *rp;
-
- ws[0] = '\0';
- expand(t_pic,pic);
- if (alwaysvalid || validate_fpic(field,t_pic,typ)) {
- if (typ == _Num) {
- frac_len = _calc_frac(t_pic);
- int_len = _calc_int(t_pic);
-
- r_field = valu(field);
- fstr(ws, r_field, int_len, frac_len);
- if (strcmp(ws, field) == 0) {
- if ((strchr(pic,Pic_Z) != NULL) && (r_field == 0.0))
- fillstr(ws,strlen(t_pic),' ');
- }
- else {
- audible(Beep);
- strcpy(ws,_PicErr);
- }
-
- /*
- strip(temp_fld,field);
- r_field = strtod(temp_fld,&rp);
- if (*rp == '\0') {
- sprintf(ws,"%*.*lf",int_len,frac_len,r_field);
- if ((strchr(pic,Pic_Z) != NULL) && (r_field == 0.0))
- fillstr(ws,strlen(t_pic),' ');
- }
- else {
- audible(Beep);
- strcpy(ws,"ERR");
- }
- */
-
- }
- else {
- if (nopics && empty(field)) fillstr(ws,strlen(t_pic),' ');
- else {
- j = 0;
- tmplen = strlen(t_pic);
- for (i=0; i < tmplen; i++) {
- if (set_member(_PIC_SET,t_pic[i])) {
- ws[i] = field[j];
- j++;
- }
- else ws[i] = t_pic[i];
- }
- ws[i] = '\0';
- }
- }
- }
-
- if (flen != 0) strcopy(sout,ws,start-1,flen);
- else strcpy(sout,ws);
- return(sout);
- }
-
- bool df_quickvalid(uchar typ, str20 pic)
- {
- bool tb;
- int i,tmplen;
- set goodset;
-
- tb = True;
- if (typ != _Num) {
- set_union(goodset,_DIGITS,_PIC_SET);
- tmplen = strlen(pic);
- for(i=0; i < tmplen; i++)
- if (tb) tb = set_member(goodset,pic[i]);
- }
- else tb = (bool)(strchr(pic,Pic_Z) == NULL);
- return(tb);
- }
-
- void dsp_fld(int xpos, int ypos, strptr field, uchar typ, str20 pic,
- byte start, byte flen, byte attr, winptr winp)
- {
- string tmpstr;
-
- if (attr == 0) attr = attrib;
- else if (attr == 255) attr = 0;
-
- if (strchr(pic,Pic_B) == NULL) {
- if (start < 1) start = 1;
- if (df_quickvalid(typ,pic)) {
- if (flen < 1) flen = (byte) strlen(field);
- writewxy(strcopy(tmpstr,field,start-1,flen),attr,(byte) xpos,(byte) ypos,winp);
- }
- else
- writewxy(pic_fld(tmpstr,field,typ,start,flen,pic),attr,(byte) xpos,(byte) ypos,winp);
- }
- else {
- strcpy(tmpstr,"\xff\x1 ");
- tmpstr[2] = (byte)strlen(field);
- writewxy(tmpstr,attr,(byte) xpos,(byte) ypos,winp);
- }
- }
-
- void incr_flen(int incr)
- {
- string tmpstr;
-
- if ((picptr_ < start_) || (picptr_ >= (start_+flen_))) {
- start_ += incr;
- writewxy(strcopy(tmpstr,ts_,start_-1,flen_),attr_,(byte) xpos_,(byte) ypos_,NULL);
- }
- else txpos_ += incr;
- }
-
- void next_char(int dirn)
- {
- int incr;
- uchar cstr[2];
-
- if (((dirn == Left) && (picptr_ > 1)) ||
- ((dirn == Right) && (picptr_ < strlen(t_pic_)))) {
- incr = (dirn == Right) ? 1 : -1;
- picptr_ += incr;
-
- if (flen_ > 0) incr_flen(incr);
- else txpos_ += incr;
-
- while ((!set_member(_PIC_SET,t_pic_[picptr_-1])) &&
- (((dirn == Left) && (picptr_ > 1)) ||
- ((dirn == Right) && (picptr_ < strlen(t_pic_))))) {
- if (typ_ == _Num) {
- writewxy(chstr(cstr,*_dcpt),attr_,(byte) txpos_,(byte) ypos_,NULL);
- ts_[picptr_-1] = *_dcpt;
- }
- picptr_ += incr;
- if (flen_ > 0) incr_flen(incr);
- else txpos_ += incr;
- }
- }
- else if ((kb_char_ != EndKey) && (strlen(field_) != 1)) noise(6000,0.01);
- lastchar_ = (bool) ((picptr_ == 1) || (picptr_ == strlen(ts_)));
- if (!set_member(_PIC_SET,t_pic_[picptr_-1])) {
- next_char((dirn+1) % 2);
- lastchar_ = True;
- noise(6000,0.01);
- }
- }
-
- void fixts(int dirn)
- {
- int b,tpiclen;
-
- tpiclen = strlen(t_pic_);
- if (dirn == Right) {
- for (b=picptr_; b < tpiclen-1; b++)
- if (!set_member(_PIC_SET,t_pic_[b])) {
- ts_[b+1] = ts_[b];
- ts_[b] = t_pic_[b];
- }
- if (!set_member(_PIC_SET,t_pic_[tpiclen-1])) ts_[strlen(ts_)-1] = t_pic_[tpiclen-1];
- }
- else {
- for (b=tpiclen-1; b >= picptr_-1; b--)
- if (!set_member(_PIC_SET,t_pic_[b])) {
- ts_[b-1] = ts_[b];
- ts_[b] = t_pic_[b];
- }
- if (!set_member(_PIC_SET,t_pic_[0])) ts_[0] = t_pic_[0];
- }
- }
-
- void add_char(void)
- {
- bool negamt;
- string tmpstr,tmpstr1;
- int tslen;
-
- if (ins_flag && (typ_ != _Num)) {
- tslen = strlen(ts_);
- strinsert(chstr(tmpstr,kb_char_),ts_,picptr_-1);
- ts_[tslen] = '\0';
- fixts(Right);
- next_char(Right);
- if (strchr(t_pic_,Pic_B) == NULL) {
- if (flen_ == 0) writewxy(ts_,attr_,(byte) xpos_,(byte) ypos_,NULL);
- else writewxy(strcopy(tmpstr,ts_,start_-1,flen_),attr_,(byte) xpos_,(byte) ypos_,NULL);
- }
- }
- else {
- if (typ_ == _Num) {
- if (kb_char_ == *_dcpt) {
- if ((frac_len_ == 0) || (picptr_ > (int_len_ - frac_len_))) {
- noise(1000,0.1);
- goodch = False;
- }
- else {
- negamt = (bool) (strchr(ts_,'-') != NULL);
- strcpy(ts_,fstr(tmpstr,valu(strcopy(tmpstr1,ts_,0,picptr_-1)),int_len_,frac_len_));
- picptr_ = int_len_ - frac_len_;
- if (negamt && (valu(ts_) == 0.0) && (picptr_ > 2)) ts_[picptr_-3] = '-';
- txpos_ = xpos_ + picptr_;
- picptr_++;
- writewxy(ts_,attr_,(byte) xpos_,(byte) ypos_,NULL);
- }
- }
- else {
- ts_[picptr_-1] = kb_char_;
- writewxy(chstr(tmpstr,kb_char_),attr_,(byte) txpos_,(byte) ypos_,NULL);
- next_char(Right);
- }
- }
- else {
- ts_[picptr_-1] = kb_char_;
- if (t_pic_[picptr_-1] == Pic_B)
- writewxy(" ",attr_,(byte) txpos_,(byte) ypos_,NULL);
- else
- writewxy(chstr(tmpstr,kb_char_),attr_,(byte) txpos_,(byte) ypos_,NULL);
- next_char(Right);
- }
- }
- gotoxy(txpos_,ypos_);
- }
-
- void _editf(void)
- {
- int i,tslen;
- string tmpstr,tmpstr1;
- bool specch,redisp;
-
- redisp = False;
- exit_flag_ = False;
- exitcode = 0;
- picptr_ = 1;
- txpos_ = xpos_;
- while (!set_member(_PIC_SET,t_pic_[picptr_-1])) next_char(Right);
-
- if ((edt_spos != 0) && (edt_spos <= (byte) strlen(field_)))
- for (i=1; i < edt_spos; i++) next_char(Right);
-
- gotoxy(txpos_,ypos_);
- do {
- goodch = True;
- specch = False;
- if (edthook != NULL) edthook(txpos_,ypos_,winp_);
- kb_char_ = getkey();
- if (kb_char_ == aF1) {
- specch = selectchar(&kb_char_,0,0);
- if (flen_ == 0) writewxy(ts_,attr_,(byte) xpos_,(byte) ypos_,NULL);
- else writewxy(strcopy(tmpstr,ts_,start_-1,flen_),attr_,(byte) xpos_,(byte) ypos_,NULL);
- if (!specch) kb_char_ = ts_[picptr_];
- curfun(_SetCTyp, cursptr_);
- }
- /*************************************************************************
- * [DG] 09/10/92 -- Added CtrlEnter to KB_Char test, allowing CtrlEnter *
- * to trigger exit. This is necessary because CtrlEnter *
- * will not register as an extended key, so _XKey will *
- * be false. Also added Tab and STab. *
- *************************************************************************/
- if ((_xkey && (set_member(ExitSet,kb_char_))) || (kb_char_ == Enter)
- || (kb_char_ == QitKey) || (kb_char_ == Tab) || (kb_char_ == STab)
- || (kb_char_ == CtrlEnter))
- {
- /*************************************************************************
- * [DG] 09/10/92 -- If CtrlEnter was pressed, remap it to F10, and set *
- * _XKey to true, so CtrlEnter registers as F10. *
- * [DG] 09/11/92 -- Mapped STab to UArr and Tab to DArr. Also, since the *
- * remapping allows kb_char_ to get "out-of-sync" with *
- * exitcode, so I reassigned the two. *
- *************************************************************************/
- switch (kb_char_) {
- case CtrlEnter : exitcode = F10; _xkey = True; break;
- case Tab : exitcode = DArr; break;
- case STab : exitcode = UArr; break;
- default : exitcode = kb_char_;
- }
- kb_char_ = exitcode;
- /*****************/ /* [DG] End Modifications */ /***********************/
- exit_flag_ = True;
- }
- else {
- if ((_xkey || (kb_char_ < 32)) && !specch) {
- goodch = False;
- lastchar_ = False;
- rub_flag_ = False;
- switch (kb_char_) {
- case BackSp :
- case LArr :
- next_char(Left);
- if ((kb_char_ == BackSp) && (typ_ == _Ch)) {
- redisp = True;
- if (ins_flag) {
- strconcat(tmpstr,strcopy(tmpstr,ts_,0,picptr_-1),
- strcopy(tmpstr1,ts_,picptr_,strlen(ts_)-picptr_)," ",NULL);
- strcpy(ts_,tmpstr);
- fixts(Left);
- }
- else ts_[picptr_-1] = ' ';
- }
- break;
- case CtrlLArr :
- if (!set_member(_WORDSET,ts_[picptr_-2])) {
- do {
- next_char(Left);
- }while ((!set_member(_WORDSET,ts_[picptr_-1])) && !lastchar_);
- }
- while ((set_member(_WORDSET,ts_[picptr_-2])) && !lastchar_)
- next_char(Left);
- break;
- case RArr :
- next_char(Right);
- break;
- case CtrlRArr :
- if (set_member(_WORDSET,ts_[picptr_-1])) {
- do {
- next_char(Right);
- }while (set_member(_WORDSET,ts_[picptr_-2]) && !lastchar_);
- }
- while ((!set_member(_WORDSET,ts_[picptr_-1])) && !lastchar_)
- next_char(Right);
- if (lastchar_)
- while (ts_[picptr_-1] == Space) next_char(Left);
- break;
- case Del :
- redisp = True;
- strdelete(ts_,picptr_-1,1);
- if (typ_ == _Num) {
- if (picptr_ > (int_len_ - frac_len_)) strcat(ts_,"0");
- else strinsert(" ",ts_,0);
- }
- else {
- strcat(ts_," ");
- fixts(Left);
- }
- break;
- case Ins :
- toggleins(cursptr_);
- break;
- case ClrKey :
- redisp = True;
- tslen = strlen(ts_);
- while (picptr_ <= tslen) {
- if (set_member(_PIC_SET,t_pic_[picptr_-1])) ts_[picptr_-1] = ' ';
- picptr_++;
- }
- picptr_ = 1;
- txpos_ = xpos_;
- start_ = 1;
- while (!set_member(_PIC_SET,t_pic_[picptr_-1])) next_char(Right);
- break;
- case Home :
- picptr_ = 1;
- txpos_ = xpos_;
- redisp = (bool) (start_ > 1);
- start_ = 1;
- while (!set_member(_PIC_SET,t_pic_[picptr_-1])) next_char(Right);
- break;
- case EndKey :
- next_char(Right);
- if (lastchar_ && (ts_[picptr_-1] == ' ')) {
- do {
- next_char(Left);
- }while (!lastchar_ && (ts_[picptr_-1] == ' '));
- if (ts_[picptr_-1] != ' ') next_char(Right);
- }
- else {
- if (*strip(tmpstr,strcopy(tmpstr1,ts_,picptr_-1,strlen(ts_)-picptr_+1)) == '\0') {
- do {
- next_char(Right);
- }while (!lastchar_);
- }
- else {
- i = strlen(trim(tmpstr,ts_));
- do {
- next_char(Right);
- }while (!lastchar_ && (picptr_ <= i));
- }
- }
- break;
- /*************************************************************************
- * [DG] 09/10/92 -- Commented out Tab and STab so these two keys can be *
- * used to change fields. *
- *************************************************************************/
- /*
- case Tab :
- for (i=1; i <= _Tab_Space; i++) next_char(Right);
- break;
- case STab :
- for (i=1; i <= _Tab_Space; i++) next_char(Left);
- break;
- */
- }
- if (redisp) {
- redisp = False;
- if (strchr(t_pic_,Pic_B) == NULL) {
- if (flen_ == 0) writewxy(ts_,attr_,(byte) xpos_,(byte) ypos_,NULL);
- else writewxy(strcopy(tmpstr,ts_,start_-1,flen_),attr_,(byte) xpos_,(byte) ypos_,NULL);
- }
- }
- gotoxy(txpos_,ypos_);
- }
- else {
- if ((set_member(_NUMERIC,kb_char_)) && (kb_char_ != ' ') && rub_flag_) {
- fillstr(ts_,strlen(field_),' ');
- writewxy(ts_,attr_,(byte) xpos_,(byte) ypos_,NULL);
- rub_flag_ = False;
- }
- switch (t_pic_[picptr_-1]) {
- case PIC_B :
- case PIC_X :
- add_char();
- break;
- case PIC_A :
- if (set_member(_ALPHA,kb_char_)) add_char();
- else {
- goodch = False;
- noise(1000,0.1);
- }
- break;
- case PIC_Z :
- case PIC_H :
- if (set_member(_NUMERIC,kb_char_)) {
- if ((typ_ != _Ch) && (kb_char_ == ' ')) {
- noise(1000,0.1);
- goodch = False;
- }
- else add_char();
- }
- else {
- noise(1000,0.1);
- goodch = False;
- }
- break;
- case PIC_U :
- kb_char_ = upperch(kb_char_);
- add_char();
- break;
- case PIC_L :
- kb_char_ = lowerch(kb_char_);
- add_char();
- break;
- case PIC_S :
- if ((picptr_ == 1) || (set_member(_SPLITSET,ts_[picptr_-2])))
- kb_char_=upperch(kb_char_);
- add_char();
- break;
-
- }
- }
- }
- } while ((!exit_flag_) &&
- !((strlen(ts_) == 0) && (!_1chwait) && goodch));
- if (edt_spos != 0) edt_spos = (byte) picptr_;
- }
-
- void edt_fld(int xPos, int yPos, strptr field, uchar typ, str20 pic,
- byte flen, byte a, winptr winp)
- {
- int tslen;
- double r_field;
- string t_field,tmpstr;
- char *rp,*tp;
- cursortyp tcurs;
-
- xpos_ = xPos;
- ypos_ = yPos;
- field_ = field;
- typ_ = typ;
- pic_ = pic;
- flen_ = flen;
- a_ = a;
- winp_ = winp;
- nopics = False;
- strcpy(savefield_, field_);
- attr_ = _ev;
-
- dsp_fld(xpos_, ypos_, field_, typ_, pic_, 0, (byte) flen_, attr_, winp_);
- if (badpic) {
- exitcode = QitKey;
- badpic = False;
- }
- else {
- if (winp_ != NULL) {
- xpos_ += winp_->mx - 1;
- ypos_ += winp_->my - 1;
- cursptr_ = &winp_->curs;
- }
- else cursptr_ = db_malloc(sizeof(cursptr_));
-
- curfun(_GetCurs,&tcurs);
- start_ = 1;
- expand(t_pic_,pic_);
- pic_fld(ts_,field_,typ_,0,0,pic_);
- rub_flag_ = False;
- if (start_ == 0) start_ = 1;
- ins_flag = (bool) (!ins_flag);
- toggleins(cursptr_);
- if (typ_ == _Num) {
- flen_ = 0;
- rub_flag_ = True;
- frac_len_ = _calc_frac(t_pic_);
- int_len_ = _calc_int(t_pic_);
- _editf();
- if (exitcode == QitKey) strcpy(ts_,"0");
- fstr(t_field, valu(ts_), int_len_, frac_len_);
-
- /*
- do {
- do {
- _editf();
- if ((exitcode == QitKey) || empty(ts_)) strcpy(ts_,"0");
- strip(t_field,ts_);
- if (t_field[0] == *_dcpt) strinsert("0",t_field,0);
- r_field = strtod(t_field,&rp);
- if (*rp != '\0') noise(1000,0.1);
- } while (*rp != '\0');
-
- sprintf(t_field,"%*.*lf",int_len_,frac_len_,r_field);
- if (strlen(t_field) > strlen(t_pic_)) noise(1000,0.1);
- } while (strlen(t_field) > strlen(t_pic_));
- */
-
- strcpy(field_,t_field);
- }
- else {
- _editf();
- field_[0] = '\0';
- tp = field_;
- tslen = strlen(ts_);
- for (txpos_ = 0; txpos_ < tslen; txpos_++)
- if (set_member(_PIC_SET,t_pic_[txpos_])) *tp++ = ts_[txpos_];
- *tp = '\0';
- }
- if (winp_ != curwin) {
- if (strchr(t_pic_,Pic_B) == NULL) {
- if (flen_ == 0) writewxy(ts_,0,(byte) xpos_,(byte) ypos_,&winscr);
- else writewxy(strcopy(tmpstr,ts_,0,flen_),0,(byte) xpos_,(byte) ypos_,&winscr);
- }
- }
- if (winp_ != NULL) {
- xpos_ = xpos_ - ((int) winp_->mx) + 1;
- ypos_ = ypos_ - ((int) winp_->my) + 1;
- }
- attr_ = (a_ == 0) ? attrib : a_;
- nopics = True;
- dsp_fld(xpos_,ypos_,field_,typ_,pic_,0,(byte) flen_,attr_,winp_);
- /*************************************************************************
- * [DG] 09/10/92 -- Added STab to keys which trigger previous field *
- *************************************************************************/
- _upward = (bool) ((exitcode == UArr) || (exitcode == STab));
- switch (exitcode) {
- case UArr :
- case STab :
- if (fldnum > 1) fldnum--;
- break;
- case DArr :
- case Enter :
- case Tab :
- case Nul :
- fldnum++;
- break;
- }
- /**********************/ /* [DG] End Modification */ /*******************/
- }
- curfun(_SetCTyp,&tcurs);
- *cursptr_ = tcurs;
- if (winp_ == NULL) db_free(cursptr_);
- fieldchanged = (bool) (strcmp(savefield_,field_) != 0);
- }
-
- strptr format(strptr sout, string text, string picture, int width, uchar align)
- {
- string pict,tempstr,td;
- bool leadzero,alpha,leadstar,leading,dollar,negative;
- bool trimr,lsign,tsign,allsign;
- int pictlen,textlen;
- uchar *tp,*textp,*tdp,*pictp;
-
- strcpy(pict,picture); /* don't modify "picture" */
- strcpy(tempstr,text); /* don't "text" */
-
- if (*pict == '\0') fillstr(pict,width,Pic_X);
- else expand(pict,pict);
- if (*pict == '\0') chstr(pict,Pic_X);
- trimr = False;
- lsign = False;
- tsign = False;
- allsign = False;
-
- if (pict[0] == Pic_TL) {
- textp = tempstr;
- while (*textp == ' ') textp++;
- strcpy(tempstr,textp);
- strcpy(pict,&pict[1]);
- }
-
- tp = strchr(pict,'\0') - 1;
- if (*tp == Pic_TR) {
- *tp = '\0';
- trimr = True;
- }
-
- alpha = False;
- for (pictlen=0; pictlen<strlen(pict); pictlen++) {
- if ((pict[pictlen] != Pic_Z) && (pict[pictlen] != Pic_H) &&
- (pict[pictlen] != Pic_Star) && (pict[pictlen] != Pic_At) &&
- (pict[pictlen] != Pic_Plus) && (pict[pictlen] != Pic_Minus) &&
- (pict[pictlen] != Pic_Dol) && (pict[pictlen] != *_dcpt)) alpha = True;
- }
- leading = True;
- td[0] = '\0';
- if (!alpha) {
- leadstar = (bool) (strchr(pict,Pic_Star) != NULL);
- leadzero = (bool) (strchr(pict,Pic_At) != NULL);
- tp = strchr(pict,Pic_Dol);
- dollar = (bool) (tp != NULL);
- if (dollar) strcpy(tp,tp+1);
- pictlen = strlen(pict);
- if ((pict[pictlen-1] == Pic_Plus) || (pict[pictlen-1] == Pic_Minus)) {
- pictlen--;
- lsign = True;
- allsign = (bool) (pict[pictlen] == Pic_Plus);
- pict[pictlen] = '\0';
-
- }
- tp = strchr(pict,'\0') - 1;
- if ((*tp == Pic_Plus) || (*tp == Pic_Minus)) {
- tsign = True;
- allsign = (bool) (*tp == Pic_Plus);
- *tp = '\0';
- }
- tp = strchr(tempstr,Pic_Minus);
- negative = (bool) (tp != NULL);
- if (negative && (tsign || lsign)) *tp = ' ';
- tp = tempstr;
- while ((*tp == ' ') && (leadzero || leadstar)) {
- if (leadstar) *tp = Pic_Star;
- else {
- if (leadzero) *tp = '0';
- }
- tp++;
- }
- pictp = pict;
- textp = tempstr;
- tdp = td;
- textlen = strlen(tempstr);
- pictlen = strlen(pict);
- while (*pictp) {
- if ((*pictp == *_dcpt) || (*pictp == Pic_H) ||
- (*pictp == Pic_Star) || (*pictp == Pic_At)) {
- if (*textp) {
- if (*textp != ' ') leading = False;
- *tdp++ = *textp++;
- }
- else *tdp++ = ' ';
- }
- else if (*pictp == *_thou) {
- if (textlen < pictlen) {
- if (leading && !(leadzero || leadstar)) *tdp++ = ' ';
- else *tdp++ = *_thou;
- }
- }
- pictp++;
- }
- *tdp = '\0';
- strcat(td,textp);
- if (lsign) {
- if (allsign || negative) {
- if (negative) float_ins(Pic_Minus,td);
- else float_ins(Pic_Plus,td);
- }
- else strconcat(td," ",td,NULL);
- }
- else {
- tdp = strchr(td,'\0');
- if (tsign) {
- if (allsign || negative) {
- if (negative) *tdp++ = Pic_Minus;
- else *tdp++ = Pic_Plus;
- }
- else *tdp++ = ' ';
- *tdp = '\0';
- }
- }
- if (dollar) float_ins(Pic_Dol,td);
- }
- else {
- if (align != _Fill) {
- pictp = pict;
- textp = tempstr;
- tdp = td;
- while (*pictp) {
- if (set_member(_PIC_SET,*pictp)) *tdp++ = (*textp) ? *textp++ : ' ';
- else *tdp++ = *pictp;
- pictp++;
- }
- *tdp = '\0';
- }
- else strcpy(td,tempstr);
- }
- strcpy(tempstr,td);
- if (trimr) trim(tempstr,tempstr);
- switch (align) {
- case CENTRE : centre(tempstr,tempstr,width); break;
- case RIGHT : pad(tempstr,tempstr,width,Left); break;
- case LEFT : pad(tempstr,tempstr,width,Right); break;
- case FILL :
- if (width > 254) width = 254;
- fillstr(tempstr,width,tempstr[0]);
- break;
- }
- strcpy(sout,tempstr);
- return(sout);
- }
-
- bool validpath(void)
- {
- string ts;
- fspec fr;
- bool fval;
-
- chstr(ts,'-');
- if (paramcount() >= 2) {
- strcpy(ts,paramstr(1));
- strupr(ts);
- }
- if ((ts[0] != '-') && (ts[0] != '/')) {
- strcpy(datapath,ts);
- fexpand(ts,datapath);
- fval = (bool) (ts[0] != '\0');
- if (fval) strcpy(datapath,ts);
- fsplit(datapath,fr.fdir,fr.fname,fr.fext);
- }
- else fval = True;
- return (fval);
- }
-
- void editdatapath(void)
- {
- string ts;
- int dplast;
- str8 ts1;
-
- strchcat(strcpy(ts1,"67"),Pic_X);
- strcpy(ts,datapath);
- do {
- dbgetstr(ts,_Ch,LSC_DataFilePath,datapath,ts1,"",nocheck,nohelp);
- }while ((!path_ok(strip(ts,ts))) && (exitcode != QitKey));
- if (exitcode != QitKey) {
- fexpand(datapath,strip(ts,ts));
- dplast = strlen(datapath) - 1;
- if ((datapath[dplast] == '\\') && (dplast > 3)) datapath[dplast] = '\0';
- }
- }
-
- void initedit(void)
- {
- }
-
- void parmerr(int func)
- {
- byte i;
- string tmpstr;
-
- for(i=1; i <= 8; i++)
- writewxy("\xFF\x01\x50\x20",15,1,i,NULL);
- writewxy(strconcat(tmpstr,
- "****** ",LSC_SetupFileErr," ",fname_," ******",NULL),15,1,1,NULL);
- if (func > 0)
- writewxy(strconcat(tmpstr,
- LSC_InvalidParam," : ",prm_,", ",LSC_AtLine," : ",NULL),15,1,2,NULL);
- else
- writewxy(strconcat(tmpstr,LSC_UnknownCmd," : ",NULL),15,1,2,NULL);
- writewxy(parml_,15,1,3,NULL);
- getkey();
- }
-
- int decode(string parml, string prm)
- {
- uchar *equpos,*pcmd;
- int i,cmdi;
- string ts,parml1;
-
- strcpy(parml1,parml);
- equpos = strchr(parml1,'=');
- if (equpos == NULL) parmerr(0);
- strcpy(ts,equpos+1);
- strcopy(prm,ts,0,10);
- equpos[1] = '\0';
- parml1[5] = '\0';
- for (i=0; i < 5; i++)
- if (!parml1[i]) {
- parml1[i] = ' ';
- parml1[i+1] = 0;
- }
- pcmd = ParmCmd;
- for (cmdi=1; cmdi < 5; cmdi++) {
- if (strncmp(parml1,pcmd,5) == 0) break;
- pcmd += 5;
- }
- if (cmdi >= 5) {
- parmerr(0);
- cmdi = 1;
- }
- return(cmdi);
- }
-
- void readattr(pathstr fname)
- {
- FILE *attrf;
- strptr readres;
- int parmlen;
-
- strcpy(fname_,fname);
- attrf = fopen(fname,"rt");
- if (attrf != NULL) {
- parml_[0] = '\0';
- readres = fgets(parml_,80,attrf);
- while (readres != NULL) {
- strip(parml_,parml_);
- parmlen = strlen(parml_);
- if ((*parml_) && (parml_[parmlen-1] == '\n')) parml_[parmlen-1] = '\0';
- if (*parml_) {
- strupr(parml_);
- switch (decode(parml_,prm_)) {
- case 1 :
- _av = (byte) ival(prm_);
- if (!_av) parmerr(3);
- break;
- case 2 :
- _iv = (byte) ival(prm_);
- if (!_iv) parmerr(2);
- break;
- case 3 :
- _ev = (byte) ival(prm_);
- if (!_ev) parmerr(4);
- break;
- case 4 :
- if (prm_[0] == _YES) checksnow = True;
- else {
- if (prm_[0] != _NO) parmerr(6);
- else checksnow = False;
- }
- break;
- }
- }
- readres = fgets(parml_,80,attrf);
- }
- fclose(attrf);
- }
- }
-
- void writeattr(pathstr fname)
- {
- FILE *attrfile;
- string tmpstr;
-
- attrfile = fopen(fname,"wt");
- if (attrfile != NULL) {
- fprintf(attrfile,"AV=%hu\n",_av);
- fprintf(attrfile,"IV=%hu\n",_iv);
- fprintf(attrfile,"EV=%hu\n",_ev);
- fprintf(attrfile,"SNOW=%c\n",(checksnow) ? _YES : _NO);
- fclose(attrfile);
- }
- else
- dberrm(strconcat(tmpstr,LSC_CannotCreate," ",strip(tmpstr,fname),NULL));
- }
-
- strptr getcline(pathstr sout, uchar typ, strptr prog, strptr cmd)
- {
- string prompt,tmpstr;
- uchar *tp;
- string cmdline; /* converted from pathstr to string - MB */
- uchar tpic[4];
-
- exitcode = ' ';
- strcpy(cmdline,cmd);
- if (typ == _Dos)
- trim(cmdline,strconcat(cmdline,prog," ",cmdline,NULL));
- if (((typ == _Dos) || (typ == _Cmd)) && !((typ == _Dos) && cmdline[0])) {
- strcpy(prompt,(typ == _Dos) ? LSC_EnterDosCmd : LSC_EnterCmdParams);
- strcpy(tpic,"78");
- strchcat(tpic,Pic_X);
- dbgetstr(cmdline,_Ch,prompt,cmdline,tpic,"",nocheck,nohelp);
- }
- if ((typ == _Dos) || (strstr(upper(tmpstr,prog),".BAT") != NULL)) {
- if ((typ == _Dos) && (*strip(tmpstr,cmdline) == '\0')) prog[0] = '\0';
- else {
- if (strstr(upper(tmpstr,prog),".BAT") != NULL) strconcat(cmdline,prog," ",cmdline,NULL);
- strconcat(cmdline,"/C ",cmdline,NULL);
- strcpy(prog,((tp = getenv("COMSPEC")) != NULL) ? tp : "") ;
- }
- }
- strcpy(sout,cmdline);
- return(sout);
- }
-
- void doserr(word eno, string estr)
- {
- strptr e;
- string tmpstr;
-
- if (eno) {
- switch (eno) {
- case 1 : e = LSC_ExecSwapErr; break;
- case 2 : e = DOSErr2; break;
- case 3 : e = DOSErr3; break;
- case 5 : e = DOSErr5; break;
- case 6 : e = DOSErr6; break;
- case 8 : e = DOSErr8; break;
- case 10 : e = DOSErr10; break;
- case 11 : e = DOSErr11; break;
- case 15 : e = DOSErr15; break;
- case 18 : e = DOSErr18; break;
- case 152 : e = DOSErr152; break;
- default : e = LSC_UnrecognisedErr; break;
- }
- dberrm(strconcat(tmpstr,LSC_DosErrNo,istr(tmpstr,(long) eno,2)," - ",e,NULL));
- }
- }
-
- /* SN 3.5 created the whole function */
- /* At the momemnt this routine is de-activated */
-
- void db_exec(strptr aProgram, strptr cmdLine)
- {
- /*
- bool tempBoolean;
- word sfm;
- cursortyp thisCursor;
- struct text_info textInfo;
-
- if (!(strposstr(".EXE", aProgram)) && !(strposstr(".COM", aProgram)) && (strip(aProgram, aProgram) != NULL)) es_status = 11;
- else {
- es_status = 0;
- curfun(_GetCurs, &thisCursor);
- curfun(_SetCTyp, &linecurs);
-
- swapvectors();
- tempBoolean = checksnow;
- gettextinfo(&textInfo);
- textattr(15);
-
- execlp(aProgram, cmdLine, NULL);
-
- textattr(textInfo.attribute);
- if (getvmode() != textInfo.currmode) {
- textmode(textInfo.currmode);
- checksnow = tempBoolean;
- }
-
- swapvectors();
- curfun(_SetCTyp, &thisCursor);
- _fmode = sfm;
- }
- doserr(es_status, aProgram);
- resetdeltas = True;
- */
- return;
- }
-
- /* Re colours the window pointed to by WinP in colour passed in Attr */
- /* SN 3.5 */
-
- void recolor(winptr winp, byte attr)
- {
- winp->borcolr = attr;
- colorwin(attr, winp);
- return;
- }
-
- byte pickatr(byte mode, byte defaultb, byte wcol, byte hcol)
- {
- uchar rkey;
- byte b,b1,b2,*pb;
- int mupdn;
- uchar s4[5];
- string tmpstr;
- uchar cs[2];
- winptr iwp0, twinp, hwinp; /* SN 3.5 */
-
- twinp = ColorPaletteWin(); /* SN 3.5 */
- if (wcol) recolor(twinp, wcol); /* SN 3.5 */
- writewxy(" ", 15, (byte)18, (byte)3, twinp); /* SN 3.5 */
- for (b = 1; b <= 15; b++) writewxy("█", b, (byte)(17 + b), 3, twinp); /* SN 3.5 */
- for (b = 0; b <= 7; b++) writewxy(" ", b, (byte)(17 + b), 3, twinp); /* SN 3.5 */
- for (b = 1; b <= 15; b++) writewxy("■", b, (byte)(17 + b), 3, twinp); /* SN 3.5 */
- hidewin(T_ON, twinp); /* SN 3.5 */
-
- /* selectwin(intwin[0]); SN 3.5 */
- /* hidewin(T_ON,intwin[0]); SN 3.5 */
- /* iwp0 = intwin[0]; Sn 3.5 */
-
- strconcat(s4,"\xFF\x01",chstr(tmpstr,(byte)(twinp->mwid-15)),"\x20",NULL);
- if (mode == 0) {
- for (b=twinp->mhgt; b >= twinp->mhgt-2; b--)
- writewxy(s4,twinp->wincolr,(byte)(twinp->mx),(byte)(twinp->my+b-1),NULL);
- }
-
- b1 = (byte) ((defaultb == 0) ? 15 : defaultb & 0x0F);
- b2 = (defaultb & 0xF0) >> 4;
- pb = &b1;
- mupdn = 0;
- do {
- if (pb == &b1) {
- writewxy(chstr(cs,24),(byte)(twinp->wincolr+0x80),(byte)(twinp->mwid-31+b1),4,twinp);
- if (mode > 0)
- writewxy(chstr(cs,25),twinp->wincolr,(byte)(twinp->mwid-31+b2),5,twinp);
- }
- else {
- writewxy(chstr(cs,24),twinp->wincolr,(byte)(twinp->mwid-31+b1),4,twinp);
- writewxy(chstr(cs,25),(byte)(twinp->wincolr+0x80),(byte)(twinp->mwid-31+b2),5,twinp);
- }
- for (b=1; b <= 4; b++)
- attrwritewxy(13,(byte)(b1 | (b2 << 4)),(byte)(twinp->mwid-13),(byte)(b+2),twinp);
-
- writewxy(istr(tmpstr,(long) (b1 | (b2 << 4)),3),0,(byte)(twinp->mwid-5),1,twinp);
- writewxy(hexs(tmpstr,b1 | (b2 << 4),3),0,(byte)(twinp->mwid-5),8,twinp);
- rkey = getkey();
- writewxy(" ",twinp->wincolr,(byte)(twinp->mwid-31+b1),4,twinp);
- writewxy(" ",twinp->wincolr,(byte)(twinp->mwid-31+b2),5,twinp);
- if (mousekey && ((rkey == UArr) || (rkey == DArr))) {
- if ((pb == &b2) && (rkey == UArr)) mupdn++;
- else {
- if ((pb == &b1) && (rkey == DArr)) mupdn++;
- else mupdn = 0;
- }
- if (mupdn < 3) rkey = ' ';
- else mupdn = 0;
- }
- else mupdn = 0;
-
- switch (rkey) {
- case UArr :
- case DArr :
- if (mode > 0) pb = (pb == &b1) ? &b2 : &b1;
- break;
- case LArr : *pb = ((byte) (*pb-1)) % 16; break;
- case RArr : *pb = (*pb+1) % 16; break;
- case HlpKey :
- hwinp = ColorPaletteHelp(); /* SN 3.5 */
- if (hcol) recolor(hwinp, hcol); /* SN 3.5 */
- disphelpwin(hwinp); /* SN 3.5 */
- closewin(&hwinp); /* SN 3.5 */
- break;
- }
- if ((b1 == 0) && (b1 == b2)) b1++;
- } while ((rkey != Enter) && (rkey != QitKey));
- exitcode = rkey;
- closewin(&twinp); /* SN 3.5 */
-
- /* hidewin(T_OFF,twinp); SN 3.5 */
-
- return ((rkey == QitKey) ? defaultb : (b1 | (b2 << 4)));
- }
-
- bool selectchar(uchar *tc, byte wcol, byte hcol)
- {
- byte i,j,xp,yp;
- uchar ch;
- winptr twinp, hwinp;
- uchar cs[2];
- bool sc_result;
- uchar ts1[4];
-
- sc_result = False;
- if (openwin(0,7,3,Across,Down,31,31,8,"─┐│┘─└│┌",TopCnt,"")) {
- twinp = curwin;
- twinp->disp = True;
- dispwindow(twinp);
- for (i=1; i < 33; i++) {
- Selectable[8][i*2-1] = i;
- Selectable[9][i*2-1] = i+127;
- Selectable[10][i*2-1] = i+159;
- Selectable[11][i*2-1] = i+191;
- Selectable[12][i*2-1] = i+223;
- }
-
- Selectable[12][63] = 127;
- for (i=0; i < Down; i++) writewxy(Selectable[i],31,1,(byte)(i+1),twinp);
- xp = lschx-1;
- yp = lschy-1;
-
- do {
- writewxy(istr(ts1, Selectable[yp][xp], 3), 0,(byte)(twinp->mx),(byte)(twinp->my - 1), NULL);
- writewxy(chstr(cs,Selectable[yp][xp]),0xF0,(byte)(xp+1),(byte)(yp+1),twinp);
- ch = getkey();
- writewxy(chstr(cs,Selectable[yp][xp]),31,(byte)(xp+1),(byte)(yp+1),twinp);
- switch (ch) {
- case HlpKey :
-
- /* disphelpwin(intwin[2]); SN 3.5 */
-
- hwinp = PickChHelp(); /* SN 3.5 */
- if (hcol) recolor(hwinp, hcol); /* SN 3.5 */
- disphelpwin(hwinp); /* SN 3.5 */
- closewin(&hwinp); /* SN 3.5 */
- break;
- case F2 :
- case Enter :
- case QitKey : break;
- case UArr :
- if (yp > 0) {
- j = yp;
- do {
- yp--;
- }while ((Selectable[yp][xp] == ' ') && (yp > 0));
- if (Selectable[yp][xp] == ' ') yp = j;
- }
- break;
- case DArr :
- if (yp < Down-1) {
- j = yp;
- do {
- yp++;
- }while ( (Selectable[yp][xp] == ' ') && (yp < Down-1) );
- if (Selectable[yp][xp] == ' ') yp = j;
- }
- break;
- case LArr :
- if (xp > 0) {
- j = xp;
- do {
- xp--;
- }while ( (Selectable[yp][xp] == ' ') && (xp > 0) );
- if (Selectable[yp][xp] == ' ') xp = j;
- }
- break;
- case RArr :
- if (xp < Across-1) {
- j = xp;
- do {
- xp++;
- }while ( (Selectable[yp][xp] == ' ') && (xp < Across-1) );
- if (Selectable[yp][xp] == ' ') xp = j;
- }
- break;
- }
- } while(((ch < ' ') || (ch > '~')) && (ch != QitKey) && (ch != Enter) && (ch != F2) );
- if (ch != QitKey) {
- sc_result = True;
- lschx = xp+1;
- lschy = yp+1;
- *tc = (ch == Enter) ? Selectable[yp][xp] : ch;
- }
- else sc_result = False;
- closewin(&twinp);
- }
- return(sc_result);
- }
-
- void get_pat_n_nam(strptr name, extstr extn)
- {
- fspec fr;
- string ts;
- uchar *tp;
- int slen;
-
- chstr(ts,'-');
- if (paramcount() > 1) strupr(strcpy(ts,paramstr(1)));
- if ((*ts != '-') && (*ts != '/')) {
- fexpand(fr.fpath,ts);
- if ((dotPos(fr.fpath) >= 0) && !(path_ok(fr.fpath)))
- *(fr.fpath + dotPos(fr.fpath) + 1 ) = '\0';
- strcat(fr.fpath,extn);
- if (!exists(fr.fpath)) {
- tp = fr.fpath + strlen(fr.fpath) - strlen(extn);
- *tp = '\0';
- if (!path_ok(fr.fpath)) {
- while ( fr.fpath[0] && (*(tp-1) != '\\')) {
- tp--;
- *tp = '\0';
- }
- if (!path_ok(fr.fpath)) {
- getcurrentdir(fr.fpath,0);
- tp = strchr(fr.fpath,'\0');
- }
- }
- if (*(tp-1) != '\\') {
- *tp++ = '\\';
- *tp = '\0';
- }
- }
- }
- else {
- getcurrentdir(fr.fpath,0);
- tp = strchr(fr.fpath,'\0');
- if (*(tp-1) != '\\') {
- *tp++ = '\\';
- *tp = 0;
- }
- }
- fsplit(fr.fpath,fr.fdir,fr.fname,fr.fext);
- strcpy(datapath,fr.fdir);
- slen = strlen(datapath);
- if ((slen > 3) && (datapath[slen - 1] == '\\')) datapath[slen-1] = 0;
- strconcat(name,fr.fname,fr.fext,NULL);
- if (name[0]) strconcat(name,datapath,"\\",name,NULL);
- if ( (tp = strstr(name,"\\\\")) != NULL) strcpy(tp,tp+1);
- }
-
- strptr npart(pathstr sout, pathstr ps)
- {
- uchar *fvp,*psp;
-
- fvp = sout;
- psp = ps;
- while (*psp) {
- if ((*psp != ' ') && (*psp != '\\')) *fvp++ = *psp;
- psp++;
- }
- *fvp = '\0';
- return(sout);
- }
-
- void sortdirarray(void)
- {
- int i,j;
- dirnamstr ts;
- uchar *tp;
-
- for (i=0; i < countf_-1; i++) {
- tp = (*dirarray_)[i];
- for(j=i+1; j < countf_; j++)
- if (strcmp((*dirarray_)[j],tp) < 0) tp = (*dirarray_)[j];
- strcpy(ts,(*dirarray_)[i]);
- strcpy((*dirarray_)[i],tp);
- strcpy(tp,ts);
- }
- }
-
- void fix254s(void)
- {
- int i,numf,numd,blanks;
- uchar *tp;
-
- numf = countf_;
- numd = 0;
- while ((numf > 0) && (*(tp = (*dirarray_)[numf-1]) == 254)) {
- if (strstr(tp,"..\\") != NULL) pad(tp,LSC_ParentDir,ColSz-1,Right);
- else pad(tp,strcat(strcpy(tp,strip(tp,tp)+1),"\\"),ColSz-1,Right);
- numf--;
- numd++;
- }
- if ((numd > 0) && (numd != countf_)) {
- blanks = Colms - (numf % Colms);
- if (blanks < Colms) blanks += Colms;
- for (i=blanks+numd-1; i >= 0; i--) {
- if (i >= blanks) strcpy((*dirarray_)[countf_+i-numd],(*dirarray_)[countf_+i-(blanks+numd)]);
- else pad((*dirarray_)[countf_+i-numd],"",ColSz-1,Right);
- }
- countf_ += blanks;
- }
- }
-
- void step(int s)
- {
- string tmpstr;
-
- do {
- if ((apos_+s) >= countf_) s = countf_-apos_-1;
- else {
- if ((apos_+s) < 0) s = -apos_;
- }
-
- apos_ += s;
- col_ += s;
- if (col_ > Colms) {
- col_ %= Colms;
- if (col_ == 0) col_ = Colms;
- lin_++;
- if (lin_ > Lines) {
- lin_--;
- tpage_ += Colms;
- refill_ = True;
- }
- }
- else {
- if (col_ <= 0) {
- col_ = (col_ % Colms)+Colms;
- if (col_ == 0) col_ = Colms;
- lin_--;
- if (lin_ <= 0) {
- lin_++;
- tpage_ -= Colms;
- refill_ = True;
- }
- }
- }
- } while (*strip(tmpstr,(*dirarray_)[apos_]) == 0);
- }
-
- strptr dirpick(strptr sout, pathstr mask, word include, word exclude, byte wcol, byte hcol)
- {
- int fatr,err,maxstore,x,y;
- uchar ukey;
- word allocated;
- pathstr dirpart,savd,savp,mask_,tmask1,tmask2;
- dirnamstr search,savsch,fname,dsppic;
- findrec srchrec;
- winptr twinp, hwinp;
- bool newdir;
- uchar *tp,*dap;
- string ts,ts1;
- int tlen;
- bool posresult,findok;
- byte saveswc, savesbc;
-
-
- saveswc = swc;
- savesbc = sbc;
-
- strcpy(mask_,mask);
- *sout = '\0';
- x = strlen(mask_) - 1;
- while ((x >= 0) && (mask_[x] != ':') && (mask_[x] != '\\')) x--;
- strcpy(tmask1,&mask_[x+1]);
-
- x = (scrwid-(Colms*ColSz+2))/2;
- if ((allocavail((MinDirSpace + (Colms * ((ColSz * Lines) + 2))))) == (MinDirSpace + (Colms * ((ColSz * Lines) + 2)))) {
- if (wcol) {
- swc = wcol;
- sbc = wcol;
- }
- if (openwin(0,x,5,Colms*ColSz,Lines+2,swc,sbc,8,"─┐│┘─└│┌",TopCnt,tmask1)) {
- twinp = curwin;
- twinp->disp = True;
- dispwindow(twinp);
- writewxy(centre(ts,LSC_ChangeDrives,twinp->mwid),0,1,twinp->mhgt,twinp);
- allocated = allocavail(MaxDirEntries*sizeof(dirnamstr));
- maxstore = allocated/sizeof(dirnamstr);
- dirarray_ = db_malloc(maxstore*sizeof(dirnamstr));
- dirpart[0] = '\0';
- x = strlen(mask_)-1;
- while ((mask_[x] != '\\') && (mask_[x] != ':') && (x >= 0)) x--;
- if (x >= 0) {
- strcopy(dirpart,mask_,0,x+1);
- strcpy(mask_,&mask_[x+1]);
- }
- if ((dirpart[0] == '\0') || !path_ok(dirpart)) getcurrentdir(dirpart,0);
- tp = strchr(dirpart,'\0');
- if (*(tp-1) != '\\') {
- *tp++ = '\\';
- *tp = '\0';
- }
- do {
- countf_ = 0;
- writewxy(centre(ts,LSC_Searching,twinp->mwid),(byte)(diratr | 0x80),1,(byte)(twinp->mhgt-1),twinp);
- strip(tmask1,mask_);
- if((tp = strchr(tmask1,',')) != NULL) {
- *tp = '\0';
- strcpy(tmask2,tmask1);
- strcpy(tmask1,tp+1);
- }
- else {
- strcpy(tmask2,tmask1);
- tmask1[0] = '\0';
- }
- fatr = include & (0xFF ^ A_DIREC);
- findok = db_findfirst(strconcat(ts,dirpart,tmask2,NULL),&srchrec,fatr);
- do {
- if (findok && ((srchrec.attrib & exclude) == 0) &&
- (((srchrec.attrib & fatr) != 0) || (srchrec.attrib == 0))) {
- countf_++;
- pad((*dirarray_)[countf_-1],srchrec.name,ColSz-1,Right);
- }
- findok = db_findnext(&srchrec);
- while (!findok && *tmask1) {
- if ((tp = strchr(tmask1,',')) != NULL) {
- *tp = '\0';
- strcpy(tmask2,tmask1);
- strcpy(tmask1,tp+1);
- }
- else {
- strcpy(tmask2,tmask1);
- tmask1[0] = '\0';
- }
- findok = db_findfirst(strconcat(ts,dirpart,tmask2,NULL),&srchrec,fatr);
- }
- } while (findok && ((countf_+(2*Colms)) < maxstore));
- if (!findok && ((exclude & A_DIREC) == 0)) {
- fatr = A_DIREC;
- findok = db_findfirst(strconcat(ts,dirpart,"*.*",NULL),&srchrec,fatr);
- do {
- if (findok && ((srchrec.attrib & fatr) != 0) &&(strcmp(srchrec.name,".") != 0) &&
- (strcmp(srchrec.name,"..") != 0)) {
- countf_++;
- tp = (*dirarray_)[countf_-1];
- pad(tp,strconcat(tp,"\xFE",srchrec.name,NULL),ColSz-1,Right);
- }
- findok = db_findnext(&srchrec);
- } while (findok && ((countf_+(2*Colms)) < maxstore));
- }
- if ((strlen(dirpart) > 3) && ((exclude & A_DIREC) == 0)) {
- countf_++;
- pad((*dirarray_)[countf_-1],"\xFE\xFE..\\",ColSz-1,Right);
- }
- sortdirarray();
- fix254s();
- search[0] = '\0';
- strconcat(dsppic,"12",chstr(ts,Pic_U),NULL);
- refill_ = True;
- tpage_ = 0;
- col_ = 1;
- lin_ = 1;
- apos_ = 0;
- do {
- newdir = False;
- if (refill_) {
- writewxy(centre(ts,dirpart,twinp->mwid),diratr,1,(byte)(twinp->mhgt-1),twinp);
- for (y=1; y <= Lines; y++) {
- for (x=1; x <= Colms; x++) {
- err = (y-1)*Colms+x+tpage_;
- if (err <= countf_)
- strcpy(fname,(*dirarray_)[err-1]);
- else
- strconcat(fname,"\xFF\x01",chstr(ts,ColSz-1)," ",NULL);
- writewxy(fname,0,(byte) ((x-1)*ColSz+2),(byte) y,twinp);
- }
- }
- refill_ = False;
- }
- x = twinp->wid - 2 - strlen(search);
- strconcat(ts,search,"\xFF\x01",chstr(ts,(uchar) x),
- chstr(ts1,twinp->borchrs[4]),NULL);
- writewxy(ts,0,(byte)(twinp->x+1),(byte)(twinp->y+twinp->hgt),NULL);
- hilite((byte) ((col_-1)*ColSz+2),(byte) lin_,ColSz-1,diratr,0,twinp);
- ukey = getkey();
- if ((ukey >= 'a') && (ukey <= 'z'))
- ukey -= 'a'-'A';
- strcpy(savsch,search);
- search[0] = '\0';
- if (_ckey && (ukey >= CtrlA) && (ukey <= CtrlZ)) {
- if (ukey != dirpart[0]) {
- strcpy(savp,dirpart);
- getcurrentdir(savd,0);
- getcurrentdir(dirpart,ukey);
- if (!changedir(dirpart)) {
- doserr(_doserrno,dirpart);
- strcpy(dirpart,savp);
- ukey = ' ';
- }
- else {
- tp = strchr(dirpart,'\0');
- if (*(tp-1) != '\\') {
- *tp++ = '\\';
- *tp = '\0';
- }
- newdir = True;
- }
- changedir(savd);
- }
- }
- else if (countf_ > 0) {
-
- /* else {*/
- switch(ukey) {
- case HlpKey :
- /* disphelpwin(intwin[3]); SN 3.5 */
- hwinp = DirPickHelp();
- if (hcol) recolor(hwinp, hcol);
- disphelpwin(hwinp);
- closewin(&hwinp);
- break;
- case Enter :
- dap = (*dirarray_)[apos_];
- if (empty(dap))
- ukey = ' ';
- else {
- tp = LSC_ParentDir;
- tlen = strlen(tp);
- posresult = (bool) (strncmp(tp,dap,tlen) == 0);
- if (posresult || (strchr(dap,'\\') != NULL)) {
- if (posresult)
- fexpand(dirpart,strcat(dirpart,"..\\"));
- else
- fexpand(dirpart,strcat(dirpart,strip(ts,dap)));
- if (dirpart[4] == '\0')
- dirpart[3] = '\0';
- newdir = True;
- }
- }
- break;
- case LArr : step(-1); break;
- case RArr : step(1); break;
- case UArr : step(-4); break;
- case DArr : step(4); break;
- case PgUp :
- y = (lin_ > 1) ? lin_-1 : Lines;
- for (x=1; x <= y; x++) step(-4);
- break;
- case PgDn :
- y = (lin_ < Lines) ? Lines-lin_ : Lines;
- for (x=1; x <= y; x++) step(4);
- break;
- case Home :
- refill_ = (bool) (tpage_ > 0);
- apos_ = 0;
- tpage_ = 0;
- col_ = 1;
- lin_ = 1;
- break;
- case EndKey :
- apos_ = countf_-1;
- refill_ = True;
- col_ = (apos_+1) % Colms;
- if (col_ == 0) col_ = Colms;
- lin_ = countf_ / Colms;
- if (countf_ % Colms) lin_++;
- if (lin_ > Lines) {
- tpage_ = (lin_-Lines) * Colms;
- lin_ = Lines;
- }
- break;
- default :
- strcpy(search,savsch);
- if ((ukey == BackSp) && (search[0] != '\0'))
- search[strlen(search)-1] = '\0';
- else {
- if ((ukey != BackSp) && (strlen(search) < ColSz))
- strchcat(search,ukey);
- }
- if (search[0] != '\0') {
- while ((apos_ < countf_-1) && (strcmp(search,npart(ts,(*dirarray_)[apos_])) > 0) &&
- (strncmp(search,(*dirarray_)[apos_],strlen(search)) != 0))
- step(1);
- while ((apos_ > 0) &&
- (strcmp(search,npart(ts,(*dirarray_)[apos_])) < 0) &&
- (strncmp(search,(*dirarray_)[apos_-1],strlen(search)) == 0))
- step(-1);
- }
- break;
- }
- }
- } while (!newdir && (_ckey || ((ukey != QitKey) && (ukey != Enter))));
- } while ((ukey != QitKey) && (_ckey || newdir));
- closewin(&twinp);
- if ((ukey == Enter) && (countf_ > 0)) {
-
- /* if (ukey == Enter) {*/
- strconcat(sout,dirpart,strip(ts,(*dirarray_)[apos_]),NULL);
- strcpy(datapath,dirpart);
- if ((tlen = strlen(datapath)) != 0) datapath[tlen-1] = '\0';
- }
- db_free(dirarray_);
- }
- }
- return (sout);
- }
-
- void disphelpwin(winptr winp)
- {
- uchar resp;
- winptr twinp;
- byte tlen;
- uchar *tp;
-
- if (winp != NULL) {
- twinp = winp;
- selectwin(twinp);
- }
- else {
- tp = LSC_NoHelp;
- tlen = (byte) strlen(tp);
- if (openwin(0,(byte)((80-tlen)/2),12,(byte)(tlen+2),1,hcolr,hbcolr,hshad,hbchrs,TopCnt,"")) {
- twinp = curwin;
- writewxy(tp,0,2,1,twinp);
- }
- }
- if (twinp != NULL) {
- do {
- hidewin(T_ON,twinp);
- tp = LSC_ManualAvail;
- if (((manstate == _located) || (manstate == _opened)) &&
- (strlen(tp) < (twinp->mwid-2)) && (twinp->borchrs[0] != '\0'))
- writewxy(tp,0,(byte)(twinp->mx+1),(byte)(twinp->my+twinp->mhgt),NULL);
- resp = getkey();
- hidewin(T_OFF,twinp);
- if ((resp == HlpKey) && (morehelp != NULL)) morehelp();
- } while ((resp == HlpKey) && (winp != NULL));
- if (winp == NULL) closewin(&twinp);
- }
- }
-
- void disphelp(winptr hwin)
- {
- byte y;
- winptr twinp;
- string ts;
-
- y = (wherey() < (scrhgt - 3)) ? scrhgt - 1 : 2;
- strconcat(ts," ",LSC_EditMenu," ",NULL);
- if (openwin(0,2,y,78,1,63,63,8,"─┐│┘─└│┌",TopCnt,ts)) {
- twinp = curwin;
- writewxy(centre(ts,LSC_MemoEditMenu,78),63,1,1,twinp);
- hidewin(T_ON,twinp);
- }
- else twinp = NULL;
- disphelpwin(hwin);
- if (twinp != NULL) closewin(&twinp);
- }
-
- void dspmsge(string prompt, string msge, double respond)
- {
- byte y;
- winptr twinp;
- string ts;
-
- y = (byte) ((wherey() <= (scrhgt-5)) ? wherey() : 1);
- if (prompt[0])
- strconcat(ts," ",prompt," ",NULL);
- else
- ts[0] = '\0';
- if (openwin(0,2,y+2,78,1,79,79,8,"─┐│┘─└│┌",TopCnt,ts)) {
- twinp = curwin;
- twinp->disp = True;
- dispwindow(twinp);
- writewxy(centre(ts,msge,78),79,1,1,twinp);
- if (respond > 0.01) delayorkey(respond);
- else while(!kpressed());
- closewin(&twinp);
- }
- else {
- gotoxy(2,25);
- cwrite(centre(ts,msge,78));
- }
- }
-
- void dberrm(string erm)
- {
- audible(Error);
- dspmsge("",erm,0.0);
- getkey();
- }
-
- strptr dbgetstr(string sout, uchar typ, str80 prompt, string defaultstr,
- str20 pic, str80 ermsg, chkfunc check, helpproc help)
- {
- byte len,tlen,cx,cy;
- int ml;
- bool tb;
- string ts,tpic,tprompt;
- cursortyp tcurs;
- winptr twinp;
-
- strcpy(tprompt,prompt);
- if (strlen(tprompt) > 70) tprompt[70] = '\0';
- strconcat(tprompt," ",tprompt," : ",NULL);
- len = piclen(pic,typ); if (len==0) len = strlen(defaultstr);
- ml = len + strlen(tprompt);
- if (ml <= 78) {
- tlen = max(len,strlen(pic));
- cx = (byte) fround((scrwid-ml)/2.0) + 1;
- }
- else {
- ml = 78;
- tlen = (byte) (ml-strlen(tprompt));
- cx = 2;
- }
- strcpy(tpic,pic);
- if (tpic[0] == '\0') strchcat(strip(tpic,istr(tpic,(long) len,3)),Pic_X);
- if (typ == _Num) fstr(ts,valu(defaultstr),len,_calc_frac(tpic));
- else strcopy(ts,pad(ts,defaultstr,len,Right),0,len);
- curfun(_GetCurs,&tcurs);
- cy = (tcurs.crow >= (scrhgt-2)) ? tcurs.crow-2 : tcurs.crow+2;
- if (openwin(0,cx,cy,(byte) ml,1,_iv,_av,8,"─┐│┘─└│┌",TopCnt,"")) {
- twinp = curwin;
- writewxy(tprompt,0,1,1,twinp);
- twinp->disp = True;
- dispwindow(twinp);
- do {
- tb = True;
- edt_fld(strlen(tprompt)+1,1,ts,typ,tpic,tlen,_av,twinp);
- if ((exitcode != QitKey) && (exitcode != HlpKey)) {
- tb = check(ts);
- strcopy(ts,pad(ts,ts,len,Right),0,len);
- dsp_fld(strlen(tprompt)+1,1,ts,typ,tpic,0,tlen,_av,twinp);
- }
- if (exitcode == HlpKey) help();
- else {
- if ((ermsg[0]) && !tb && (exitcode != QitKey)) dberrm(ermsg);
- }
- /*************************************************************************
- * [DG] 09/10/92 -- Added CtrlEnter to exitcode test. *
- *************************************************************************/
- } while ((!tb || ((exitcode != Enter) && (exitcode != XeptKey)))
- && (exitcode != QitKey) && (exitcode != CtrlEnter));
- closewin(&twinp);
- }
- curfun(_SetCPos,&tcurs);
- curfun(_SetCTyp,&tcurs);
- if (exitcode == QitKey) pad(ts,defaultstr,len,Right);
- strcpy(sout,ts);
- return(sout);
- }
-
- void updexe(strptr idstr, word len)
- {
- word b,j,nr;
- long fpos;
- uchar buf[BSize];
- FILE *exef;
- int idstrlen;
-
- idstrlen = strlen(idstr);
- if ((idstrlen > 1) && (_osmajor >= 3)) {
- exef = fopen(thisprog.fpath,"r+b");
- fpos = filelength(fileno(exef))-BSize;
- if (fpos < 0) fpos = 0;
- do {
- j = 0;
- b = 0;
- fseek(exef,fpos,SEEK_SET);
- nr = fread(buf,1,BSize,exef);
- while ((j < idstrlen) && (b < nr)) {
- if (buf[b] == idstr[j]) j++;
- else j = 0;
- b++;
- }
- if (j == idstrlen) {
- fseek(exef,fpos+b-idstrlen,SEEK_SET);
- fwrite(idstr,1,len,exef);
- }
- else {
- fpos = fpos-BSize+idstrlen+2;
- if (fpos < 0) fpos = 0;
- }
- } while ((j != idstrlen) && (fpos != 0));
- fclose(exef);
- }
- }
-
- bool chkds(string instr)
- {
- return((bool) ((ival(instr) == 0) || (ival(instr) >= 5) && (ival(instr) <= MaxSecs)));
- }
-
- void setdeltas(void) {
- string ts;
- char ts1[4],ts2[3];
-
- ts2[0] = '3';
- ts2[1] = Pic_H;
- ts2[2] = '\0';
- dbgetstr(ts,_Num,LSC_ScreenSaveDelay,istr(ts1,(long) deltas,3),ts2,"",chkds,nohelp);
- if (exitcode != QitKey) deltas = (int) ival(ts);
- }
-
- void savedmessage(void)
- {
- int w,x,y;
- winptr twinp;
- str80 tm;
- int tlen;
- string ts;
-
- /* SN 3.5
- x = 0;
- for (w=1; w <= 3; w++)
- if ((tlen = strlen((*db_util_langp)[12+w])) > x)
- x = tlen;
- */
-
- x = maximum(11, strlen(LSC_ScreenSaveActive));
- x = maximum(x, strlen(LSC_PressAnyKey));
- if (openwin(0,2,2,(byte) (x+2),3,swc,sbc,0,"─┐│┘─└│┌",TopCnt,"")) {
- bg_on = False;
- twinp = curwin;
- writewxy(centre(ts,LSC_ScreenSaveActive,twinp->mwid),0,1,2,twinp);
- writewxy(centre(ts,LSC_PressAnyKey,twinp->mwid),0,1,3,twinp);
- twinp->disp = True;
- dispwindow(twinp);
- srand((word) (time(NULL) % 37));
- do {
- x = (rand() % (scrwid-twinp->mwid-3))+2;
- y = (rand() % (scrhgt-twinp->mhgt-3))+2;
- w = x-twinp->mx;
- for (x=1; x <= abs(w); x++) {
- scrollwin((byte) ((w > 0) ? _Right_ : _Left_),twinp);
- delay(5);
- }
- w = y-twinp->my;
- for (x=1; x <= abs(w); x++) {
- scrollwin((byte) ((w > 0) ? _Down_ : _Up_),twinp);
- delay(20);
- }
- for (w=1; w <= 50; w++)
- if (!kpressed()) {
- centre(tm,get_time(ts,_Full),twinp->mwid);
- writewxy(tm,0,1,1,twinp);
- delay(100);
- }
- } while (!kpressed());
- bg_on = True;
- closewin(&twinp);
- }
- }
-
- void screensave(void)
- {
- word bs;
- double tm;
- cursortyp tcurs;
- ptr savbuf;
-
- if ((&savescreenp != NULL) && (deltas >= 1)) {
- if (resetdeltas) {
- resetdeltas = False;
- savetime = realtime();
- }
- else {
- tm = realtime();
- if (abs((int) (tm-savetime)) > deltas) {
- bs = scrhgt * scrwid * 2;
- if (allocavail(bs) == bs) {
- curfun(_GetCurs,&tcurs);
- savbuf = db_malloc(bs);
- memmove(savbuf,actvid,bs);
- clrscr();
- savescreenp();
- resetdeltas = True;
- getkey();
- clrscr();
- memmove(actvid,savbuf,bs);
- db_free(savbuf);
- curfun(_SetCPos,&tcurs);
- curfun(_SetCTyp,&tcurs);
- }
- }
- }
- }
- }
-
- void readinternal(pathstr fnam, int s, int n, ptr iw)
- {
- pathstr wfnam;
- string ts;
-
- fsearch(wfnam,fnam,strconcat(ts,lookalong,";",datapath,NULL));
- if (wfnam[0]) readintwin(wfnam,s,n,iw);
- else {
- strconcat(ts,"\"",fnam,"\" ",DOSErr2,"\r\n",NULL);
- cwrite(ts);
- exit(0);
- }
- }
-
- /********************** UNIT INITIALIZATION/EXIT CODE *********************/
-
- void db_util_init(void)
- {
- string ts;
-
- if (!initialized) {
- initialized = True;
- db_crit_init();
- db_funcs_init();
- db_gvar_init();
- db_heap_init();
- db_curs_init();
- db_key_init();
- db_date_init();
- db_win_init();
- edthook = NULL;
- clrscr();
- gotoxy(1,10);
- manstate = _closed;
- nopics = True;
- badpic = False;
- alwaysvalid = True;
- deltas = 150;
- resetdeltas = True;
- savescreenp = savedmessage;
- ssave = screensave;
- morehelp = NULL;
- ewsfunc = NULL;
- iesfunc = NULL;
- sesproc = NULL;
- readattr(AttrFName);
- attrib = _av;
- _1chwait = False;
- getcurrentdir(datapath,0);
- set_make(_PIC_SET,Pic_X,Pic_A,Pic_H,Pic_U,Pic_L,Pic_S,Pic_Z,Pic_B,0);
- lschx = 8;
- lschy = 1;
- }
- }
-
- /***************************** END OF DB_UTIL.C ***************************/
-